<template>
	<view class="page">

		<view style="padding-bottom: 30rpx;background: #FFF;" class="">
			<!-- 放组件 -->
			<indexPage v-if="PageCur==0" @getPageCur='getPageCur' ref="Home"></indexPage>
			<mine v-if="PageCur==1" ></mine>
		</view>
		<view class="occupi"></view>
		<!-- 手写 tabbar-->
		<view class="tabbar">
			<view :style="{'margin':index===2?'0 10rpx':'0'}" :class="PageCur == index?'tabcli':''"
				v-for="(item,index) in tabbar" :key="index" @tap="getPageCur(index)">
				<view class="qr-code-img justify-center align-center" v-if="index===2">
					<image :src="item.url + '.png'" mode="widthFix"></image>
				</view>
				<image v-if="index!==2" :src="item.url + (PageCur == index?'':'-o') + '.png'" mode="widthFix"></image>
				<image style="visibility:hidden" v-if="index===2" :src="item.url + '.png'" mode="widthFix"></image>
				<text :style="{color:PageCur == index?'#FFF':'#FFF'}">{{item.name}}</text>
			</view>
		</view>

		<!-- <u-back-top :scroll-top="scrollTop" :mode="mode" :customStyle="customStyle" :iconStyle='iconStyle' top="100"
			z-index='1000' bottom='200'></u-back-top> -->
			<oderModal  :isShow='ticketShow' @close='ticketShowClose'>
				<view class="new-order">
					{{title}}
				</view>
			</oderModal>
	</view>
</template>

<script setup >
	// import {
	// 	tabbarList
	// } from '@/utils/constants.js'
	// 引入组件
	// 引入 
	import indexPage from '/pages/index/index.vue'
	import {
		onShow, onReady,
		onReachBottom, onPageScroll, onPullDownRefresh
	} from '@dcloudio/uni-app'
	import {
		reactive,getCurrentInstance,
		ref,
		toRefs
	} from 'vue'
	// let { proxy: that } = getCurrentInstance()
	let that = getCurrentInstance().appContext.config.globalProperties
	const data = reactive({

		oldPageCur: 0,
		PageCur: 0, //tab下标
		tabbar: [{ //tab数据
			name: '首页',
			iconNmae: 'home',
			url: '/static/home',
		},

		{
			name: '我的',
			url: '/static/mine',
			iconNmae: 'account',
		},
		],
		scrollTop: 0,
		mode: 'circle',
		iconStyle: {
			fontSize: '32rpx',
			color: '#FFF'
		},
		customStyle: {
			background: '#2979ff'
		},
	})
	const {
		scrollTop, mode, iconStyle, customStyle,
		oldPageCur,
		PageCur,
		tabbar
	} = toRefs(data)
	const getPageCur = ( index) => {
		
		if (PageCur.value == index) return
		PageCur.value = index

	}
	onPullDownRefresh(()=>{
		if (PageCur.value == 0) {
			// console.log(home.vlaue);
			Home.value.getList()
		}
	})
	onShow(() => {
		setTimeout(()=>{
			getWsMsg()
		},5000)
	
	})
	onReady(() => {
		
	})
	const title = ref('')
	const ticketShow = ref(false)
	const Home = ref(null)
	const ticketShowClose=()=>{
		Home.value.getList()
		that.$initAudio.play('/static/msg.MP3')
		ticketShow.value = false
	}
	 
	const getWsMsg=()=>{
		let data={token:uni.getStorageSync('token') || '',type:"online",ps:[],time:Math.floor(new Date().getTime() / 1000)}
		that.$socket.send(JSON.stringify(data));
		// setInterval(()=>{
		// 	ticketShow.value = !ticketShow.value
		// 	console.log('ticketShow.value',ticketShow.value);
		// },2000)
		console.log('that.$socket',that.$initAudio);
		// 接收消息  
		that.$socket.getMessage(res => {
			// console.log('接收消息', JSON.stringify(JSON.parse(res.data)));
			let msgData = JSON.parse(res.data)
			if (msgData.type == "new_order" && msgData.data && msgData.data.num) {
				title.value = "收到" + msgData.data.num + "个新的订单"
				ticketShow.value = true
				that.$initAudio.play('/static/msg.MP3')
				that.$initAudio.play('/static/new_order.MP3')
			}
		})
	}

	onPullDownRefresh(() => {
		uni.stopPullDownRefresh();
	})
	// onReachBottom(()=>{
	// 	if(PageCur.value==0){
	// 		// 在首页
	// 		console.log(home.value);
	// 	}
	// 	console.log('上拉加载=====-=-=-=');
	// })
	onPageScroll((e) => {
		scrollTop.value = e.scrollTop;
		// console.log(e,'onPageScroll');
		// scrollTop.value = e.scrollTop;
	})
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
		width: 100vw;
		background: #FFF;
		// overflow-x: hidden;
		.new-order{
			font-size: 36rpx;
		}
	}

	.occupi {
		background: #FFFFFF;
		// background: #00000000;
		width: 750rpx;
		min-height: 90rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}


	.tabbar {

		background: linear-gradient(180deg, #E53935 0%, #E35D5B 100%);
		position: fixed;
		left: 0rpx;
		bottom: 0rpx;
		width: 750rpx;
		min-height: 106rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;
		font-size: 22rpx;
		font-weight: 400;
		color: rgba(255, 255, 255, 0.87);
		z-index: 11;
		padding-top: 20rpx;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		view {
			width: 150rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			image {
				width: 38rpx;
				height: 30rpx;
				margin-bottom: 10rpx;
			}
		}

		.tabcli {
			color: rgba(0, 0, 0, 0.87);
		}

		.qr-code-img {

			position: absolute;
			top: -75rpx;
			width: 128rpx;
			height: 128rpx;
			border-radius: 50%;
			background: #C90F18;

			image {
				width: 68rpx;
				height: 68rpx;
				margin-bottom: 0;
			}

			&::after {
				content: '';
				position: absolute;
				width: 30px;
				height: 30px;
				line-height: 100px;
				display: block;
				text-align: center;
				// background-image: radial-gradient(600px at 28px 0px, #00000000 30px, #fff 30px);
				top: 40rpx;
				right: -52rpx;
				z-index: -1;
				background-image: radial-gradient(41px at 28px -10px, #00000000 30px, #fff 30px);
			}

			&::before {
				content: '';
				position: absolute;
				width: 30px;
				height: 30px;
				line-height: 100px;
				display: block;
				text-align: center;
				background-image: radial-gradient(41px at 4px -10px, #00000000 30px, #fff 30px);
				top: 40rpx;
				left: -52rpx;
				z-index: -1;
			}
		}
	}

	.popup-one-box {
		padding-top: 50rpx;
		position: relative;
		width: 600rpx;
		height: 900rpx;
		background: #FFFFFF00;
		// box-shadow: 0px 6rpx 14rpx 0px rgba(0, 0, 0, 0.16);
		border-radius: 0rpx;




		.popup-box-cancel {
			position: absolute;
			bottom: -100rpx;
			width: 78rpx;
			height: 78rpx;
			border-radius: 50%;
			background: #AEAEAE;

			image {
				width: 34rpx;
				height: 34rpx;
			}
		}



		.code-num {
			margin: 40rpx 0 30rpx;
			font-size: 30rpx;
			font-weight: 500;
			line-height: 35rpx;
		}

		.code-date {
			font-size: 24rpx;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.54);
		}

		.popup-box-input {
			margin-top: 50rpx;
			width: 357rpx;
			height: 357rpx;
			font-size: 28rpx;
			font-weight: 500;
			color: #333333;

			border: 4rpx solid;

			border-image: linear-gradient(135deg, rgba(254, 229, 230, 1), rgba(222, 220, 253, 1), rgba(254, 229, 230, 1), rgba(222, 220, 253, 1)) 4 4;
			// margin-bottom: 61rpx;
			// margin-bottom: calc(61rpx + constant(safe-area-inset-bottom));
			// margin-bottom: calc(61rpx + env(safe-area-inset-bottom));


			.popup-code {
				width: 100%;
			}
		}
	}
</style>
